/** 
 * Project Name:kaka 
 * File Name:BusinessCardHolderServiceImpl.java 
 * Package Name:com.luoran.kaka.service.impl 
 * Date:2018年12月18日上午10:53:07 
 * Copyright (c) 2018, Luoran, Inc. All Rights Reserved.
 * 
 */
package com.luoran.kaka.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.luoran.kaka.dao.IBasicInfoDao;
import com.luoran.kaka.dao.IBusinessCardHolderDao;
import com.luoran.kaka.dao.ICompanyDao;
import com.luoran.kaka.entity.BasicInfo;
import com.luoran.kaka.entity.BusinessCardHolder;
import com.luoran.kaka.entity.CompanyInfo;
import com.luoran.kaka.service.IBusinessCardHolderService;

/** 
 * @author ghl 
 * @since JDK 1.8
 * ClassName: BusinessCardHolderServiceImpl
 * date: 2018年12月18日 上午10:53:07
 *	
 */
@Service
public class BusinessCardHolderServiceImpl implements IBusinessCardHolderService {

	@Autowired
	private IBusinessCardHolderDao businessCardHolderDao;
	@Autowired
	private IBasicInfoDao basicInfoDao;
	@Autowired
	private ICompanyDao companyDao;

	/** 
	 * @param entity
	 * @return
	 * @author ghl 2018年12月18日上午10:53:08
	 * addCardToHolder:添加名片到名片夹
	 */
	@Override
	public String addCardToHolder(BusinessCardHolder entity) {
		businessCardHolderDao.insertTemplate(entity);
		return entity.getId();
	}

	/** 
	 * @param id
	 * @author ghl 2018年12月18日上午10:53:08
	 * deleteCardFromHolder:删除名片夹中的名片
	 */
	@Override
	public void deleteCardFromHolder(String id) {
		businessCardHolderDao.deleteById(id);
	}

	/** 
	 * @param openId
	 * @param type
	 * @return
	 * @author ghl 2018年12月18日上午10:53:08
	 * getCardsFromHolder:获取用户的名片夹
	 */
	@Override
	public List<Object> getCardsFromHolder(String openId, Integer type) {
		List<Object> res = new ArrayList<>();
		List<BusinessCardHolder> list = businessCardHolderDao.getCardsFromHolder(openId, type);
		if (null != list && list.size() > 0) {
			if (type == 1) {//个人名片名片夹
				for (int i = 0; i < list.size(); i++) {
					BasicInfo card = basicInfoDao.single(list.get(i).getCardId());
					res.add(card);
				}
			}else if(type == 2){
				for (int i = 0; i < list.size(); i++) {
					CompanyInfo card = companyDao.single(list.get(i).getCardId());
					res.add(card);
				}
			}
		}
		return res;
	}

}
